package cn.niit.service.impl;

import cn.niit.dao.AttendanceDao;
import cn.niit.entity.Attendance;
import cn.niit.entity.query.AttendanceQuery;
import cn.niit.service.AttendanceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 考勤表(Attendance)表服务实现类
 *
 * @author makejava
 * @since 2021-11-14 16:05:58
 */
@Service("attendanceService")
public class AttendanceServiceImpl implements AttendanceService {
    @Resource
    private AttendanceDao attendanceDao;


    @Override
    public PageInfo<Attendance> queryAll(AttendanceQuery attendanceQuery) {
        PageHelper.startPage(attendanceQuery.getPageNum(), attendanceQuery.getPageSize());
        return new PageInfo<Attendance>(attendanceDao.queryAll(attendanceQuery));
    }


    @Override
    public PageInfo<Attendance> queryByClassCode(AttendanceQuery attendanceQuery) {
        PageHelper.startPage(attendanceQuery.getPageNum(), attendanceQuery.getPageSize());
        return new PageInfo<Attendance>(attendanceDao.queryByClassCode(attendanceQuery));
    }


    @Override
    public PageInfo<Attendance> select(AttendanceQuery attendanceQuery) {
        PageHelper.startPage(attendanceQuery.getPageNum(), attendanceQuery.getPageSize());
        return new PageInfo<Attendance>(attendanceDao.select(attendanceQuery));
    }

    @Override
    public Attendance queryAttendanceById(Integer id) {
        return attendanceDao.queryAttendanceById(id);
    }

    @Override
    public boolean addAttendance(Attendance attendance) {
        return attendanceDao.addAttendance(attendance) > 0;
    }

    @Override
    public boolean editAttendance(Attendance attendance) {
        int i = attendanceDao.editAttendance(attendance);
        if (i > 0) {
            return true;
        } else {
            return false;
        }

    }

    @Override
    public boolean deleteAttendanceById(Integer id) {
        int i = attendanceDao.deleteAttendanceById(id);
        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }
}